
#import "SMMineInviteViewController.h"
#import <Masonry/Masonry.h>
@implementation SMMineInviteViewController {
    UILabel *_codeL;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.title=@"邀请好友";
    self.view.backgroundColor=UIColor.systemGroupedBackgroundColor;
    UIView *card=[UIView new];
    card.backgroundColor=UIColor.secondarySystemBackgroundColor;
    card.layer.cornerRadius=16; card.layer.masksToBounds=YES;
    [self.view addSubview:card];
    [card mas_makeConstraints:^(MASConstraintMaker *make){ make.top.equalTo(self.view.mas_safeAreaLayoutGuideTop).offset(20); make.left.equalTo(self.view).offset(16); make.right.equalTo(self.view).offset(-16);}];
    UILabel *t=[UILabel new]; t.text=@"我的邀请码"; t.textAlignment=NSTextAlignmentCenter;
    _codeL=[UILabel new]; _codeL.text=@"FG8896"; _codeL.font=[UIFont systemFontOfSize:28 weight:UIFontWeightBold]; _codeL.textAlignment=NSTextAlignmentCenter;
    UIButton *copy=[UIButton buttonWithType:UIButtonTypeSystem]; [copy setTitle:@"复制邀请码" forState:UIControlStateNormal];
    [copy addTarget:self action:@selector(copyCode) forControlEvents:UIControlEventTouchUpInside];
    [card addSubview:t]; [card addSubview:_codeL]; [card addSubview:copy];
    [t mas_makeConstraints:^(MASConstraintMaker *make){ make.top.equalTo(card).offset(18); make.left.right.equalTo(card);}];
    [_codeL mas_makeConstraints:^(MASConstraintMaker *make){ make.top.equalTo(t.mas_bottom).offset(8); make.left.right.equalTo(card);}];
    [copy mas_makeConstraints:^(MASConstraintMaker *make){ make.top.equalTo(self->_codeL.mas_bottom).offset(14); make.centerX.equalTo(card); make.bottom.equalTo(card).offset(-16);}];
}
- (void)copyCode {
    UIPasteboard.generalPasteboard.string = _codeL.text;
    UIAlertController *ac=[UIAlertController alertControllerWithTitle:@"已复制" message:_codeL.text preferredStyle:UIAlertControllerStyleAlert];
    [ac addAction:[UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:nil]];
    [self presentViewController:ac animated:YES completion:nil];
}
@end
